home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr48 / pas_0593.zip / CTRL_ALT.PAS < prev    next >
Pascal/Delphi Source File  |  1993-05-30  |  2KB  |  88 lines

  1. {─ Fido Pascal Conference ────────────────────────────────────────────── PASCAL ─
  2. Msg  : 327 of 410
  3. From : Wilbert van Leijen                  2:281/256.14         12 May 93  21:01
  4. To   : Jason Duke                          1:381/102.0
  5. Subj : Scanning for CTRL- and ALT- keys
  6. ────────────────────────────────────────────────────────────────────────────────
  7. 08 May 93, Jason Duke writes to All:
  8.  
  9.  JD> HEy, I have been using some routines to check if certain keys are pressed,
  10.  JD> but I can't figure out how to test for ALT and CTRL key combinations.
  11.  JD> Anyone want to give me some help?}
  12.  
  13. {$G+ }
  14.  
  15. uses Dos, Crt;
  16.  
  17. Var
  18.   KeyHandlerProc : Procedure;
  19.   Int15Vector  : Pointer;
  20.  
  21. Const
  22.   AltStatus    : Array[Boolean] of String[5] = ('     ', ' ALT ');
  23.   CtrlStatus   : Array[Boolean] of String[6] = ('      ', ' CTRL ');
  24.  
  25. Procedure KeyHandler; Far;
  26.  
  27. Var
  28.   AltKey       : Boolean;
  29.   CtrlKey      : Boolean;
  30.   WhereXY      : Record
  31.                    x, y : Byte;
  32.                  end;
  33. Begin
  34.   AltKey := False;
  35.   CtrlKey := False;
  36.   ASM
  37.         MOV    AH, 2
  38.         INT    16h
  39.         CMP    AL, 8
  40.         JNE    @1
  41.         INC    [AltKey]
  42. @1:     CMP    AL, 4
  43.         JNE    @2
  44.         INC    [CtrlKey]
  45. @2:
  46.   end;
  47.   WhereXY.x := WhereX;
  48.   WhereXY.y := WhereY;
  49.   GotoXY(66, 25);
  50.   Write(AltStatus[AltKey], ' ', CtrlStatus[CtrlKey]);
  51.   GotoXY(WhereXY.x, WhereXY.y);
  52. end;  { KeyHandler }
  53.  
  54. { This INT 15h handler is called every time a key is pressed -
  55.   provided you're not running this program on an XT-class machine }
  56.  
  57. Procedure TrapKeyboard; Assembler;
  58.  
  59. ASM
  60.         PUSH   BX
  61.         PUSH   DS
  62.         PUSHF
  63.         MOV    BX, SEG @Data
  64.         MOV    DS, BX
  65.         CMP    AH, 4Fh
  66.         JNE    @ChainInt15
  67.         PUSH   ES
  68.         PUSHA
  69.         CALL   [KeyHandlerProc]
  70.         POPA
  71.         POP    ES
  72.  
  73. @ChainInt15:
  74.         PUSHF
  75.         CALL   [Int15Vector]
  76.         POPF
  77.         POP    DS
  78.         POP    BX
  79.         IRET
  80. end;  { TrapKeyboard }
  81.  
  82. Begin
  83.   GetIntVec($15, Int15Vector);
  84.   KeyHandlerProc := KeyHandler;
  85.   SetIntVec($15, @TrapKeyboard);
  86.   ReadLn;
  87.   SetIntVec($15, Int15Vector);
  88. end.